package com.example.service.impl;

import com.example.mapper.ProductMapper;
import com.example.pojo.DTO.UpdateGoodDTO;
import com.example.pojo.DTO.addGoodsDTO;
import com.example.pojo.VO.GoodsDataVO;
import com.example.pojo.VO.Result;
import com.example.pojo.entrity.product;
import com.example.service.ProductService;
import com.example.utils.CreateID;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public Result addGoods(addGoodsDTO goods) {

        String id= CreateID.createUniqueID();
        product pd=new product(id,goods.getName(),goods.getDescription(),goods.getImage(),
                goods.getPrice(),goods.getStockQuantity(),goods.getCategory());
        productMapper.addGood(pd);
        return Result.success("上传成功");
    }

    @Override
    public Result getGoods() {
        log.info("按照类别区分货物");
        List<GoodsDataVO> list= productMapper.getGoods();
        return Result.success(list);
    }

    @Override
    public Result deleteProducts(List<Integer> list) {
        log.info("删除商品数据");
        productMapper.deleteProducts(list);
        return Result.success("删除成功");
    }

    @Override
    public Result selectProducts(String name) {
        List<GoodsDataVO> list=productMapper.selectGoods(name);
        return null;
    }

    @Override
    public Result updateGood(UpdateGoodDTO goodDTO) {
        productMapper.updateGood(goodDTO);
        return Result.success("修改成功");
    }

    @Override
    public Result getData(String id) {
       product p= productMapper.getData(id);
        return Result.success(p);
    }
}
